﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vds2465Telegrams
{
	public abstract class UserData_Address : UserData_Device
	{
		#region private member variables

		private readonly byte _address;
		private readonly byte _addressAddOn;

		#endregion private member variables

		#region constructor

		public UserData_Address(byte dataType, byte device, byte address, byte addressAddOn)
			: base(dataType, device)
		{
			_address = address;
			_addressAddOn = addressAddOn;
		}

		#endregion constructor

		#region getters

		public byte Address { get { return _address; } }
		public byte AddressAddOn { get { return _addressAddOn; } }

		#endregion getters

		#region ToString, Equals, GetHashCode

		public override int GetHashCode()
		{
			int hashCode = base.GetHashCode();

			hashCode ^= _address;
			hashCode ^= _addressAddOn;

			return hashCode;
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("(");
			stringBuilder.Append(ToStringProperties());
			stringBuilder.Append(")");

			return stringBuilder.ToString();
		}

		internal override string ToStringProperties()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(base.ToStringProperties());
			stringBuilder.Append(", ");

			stringBuilder.Append("Address='");
			stringBuilder.Append(Address);
			stringBuilder.Append("'");

			stringBuilder.Append(", ");

			stringBuilder.Append("AddressAddOn='");
			stringBuilder.Append(AddressAddOn);
			stringBuilder.Append("'");

			return stringBuilder.ToString();
		}

		public override bool Equals(object obj)
		{
			Type objType = obj.GetType();
			if (this.GetType() == objType)
			{
				UserData_Address userData2Compare = obj as UserData_Address;
				return EqualsProperties(userData2Compare);
			}

			return false;
		}

		internal bool EqualsProperties(UserData_Address userData2Compare)
		{
			if (base.EqualsProperties(userData2Compare))
			{
				if (Address == userData2Compare.Address)
				{
					return (AddressAddOn == userData2Compare.AddressAddOn);
				}

				return false;
			}

			return false;
		}

		#endregion ToString, Equals, GetHashCode
	}
}
